﻿
/* $Id: Program.cs 9 2011-04-20 09:17:32Z nramsbottom@gmail.com $ */

using System;
using System.Net;
using System.ServiceProcess;
using System.Diagnostics;

namespace SimpleNetServer
{
	class Program : ServiceBase
	{

		private NetServer _server = null;

		static void Main(string[] args)
		{

			var service = new Program();

			if (Environment.UserInteractive)
			{
				Debug.Listeners.Add(new ConsoleTraceListener());
				Debug.WriteLine("Server is running in interactive mode.");
				service.OnStart(args);
				Console.WriteLine("Press any key to exit...");
				Console.Read();
				service.OnStop();
			}
			else
			{
				Run(service);
			}

		} //

		protected override void OnStart(string[] args)
		{

			_server = new NetServer(IPAddress.Loopback, 1982);
			_server.Start();
			
			Debug.WriteLine("Server started.");

			base.OnStart(args);
		} //

		protected override void OnStop()
		{
			_server.Stop();
			Debug.WriteLine("Server stopped.");

			base.OnStop();
		} //

		private void InitializeComponent()
		{
			this.ServiceName = "SimpleNetServerSvc";
		} //

	} // class

} // namespace
